import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ThemeController extends GetxController {
  final _themeColor = const Color(0xFF2D9596).obs;
  final _themeKey = 'theme_color';

  Color get themeColor => _themeColor.value;

  @override
  void onInit() {
    super.onInit();
    _loadThemeColor();
  }

  Future<void> _loadThemeColor() async {
    final prefs = await SharedPreferences.getInstance();
    final colorValue = prefs.getInt(_themeKey);
    if (colorValue != null) {
      _themeColor.value = Color(colorValue);
    }
  }

  Future<void> setThemeColor(Color color) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setInt(_themeKey, color.value);
    _themeColor.value = color;
    Get.back();
    // 使用 GetX 的响应式特性强制更新所有页面
    Get.forceAppUpdate();
  }
} 